// https://leetcode.cn/problems/longest-common-prefix/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        int i = 0;
        int n = strs.size(), m = strs[0].size();

        while (i < m) {
            for (int j = 1; j < n; j++) {
                if (strs[j][i] != strs[j - 1][i]) {
                    return strs[0].substr(0, i);
                }
            }
            i++;
        }
        return strs[0].substr(0, i);
    }
};